Skip to content

fix(paste): collapse line breaks in pasted HTML - #3066

Open
Anurag-S1ngh wants to merge 1 commit into
codex-team:nextfrom
Anurag-S1ngh:fix/2350-paste-line-breaks
Open

Anurag-S1ngh wants to merge 1 commit into
codex-team:nextfrom
Anurag-S1ngh:fix/2350-paste-line-breaks

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor

Summary

Closes #2350.

HTML copied from MS Word can contain line breaks inside text nodes, for example between two inline runs. Browsers render those characters as spaces, but Editor.js saved the raw newline into the block data, so the stored JSON stopped matching what the user saw. The same happens with any pasted HTML that is pretty-printed.

Changes

  • Collapse runs of line breaks and adjacent spaces or tabs in pasted text nodes into a single space
  • Skip pre, code and textarea content so intentional line breaks are preserved

Testing

  • New test in test/cypress/tests/copy-paste.cy.ts pastes HTML with a line break and expects the saved text to contain a single space
  • Without the change the test fails
  • yarn lint
  • npx cypress run --spec test/cypress/tests/copy-paste.cy.ts
  • npx cypress run --spec test/cypress/tests/sanitisation.cy.ts
  • npx cypress run --spec test/cypress/tests/api/tools.cy.ts
  • npx cypress run --spec test/cypress/tests/api/blocks.cy.ts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pasting from MS Word places random new line characters in the paragraph text

1 participant